import request from '@/utils/request';
import { encrypt } from '@/utils/rsaEncrypt';

export function add(data) {
  return request({
    url: 'users/addUserInfo',
    method: 'post',
    data
  });
}

export function del(ids) {
  return request({
    url: 'users/delete',
    method: 'delete',
    data: ids
  });
}

export function edit(data) {
  return request({
    url: 'users',
    method: 'put',
    data
  });
}

export function editUser(data) {
  return request({
    url: 'users/center',
    method: 'put',
    data
  });
}
export function changePassword(user) {
  const data = {
    password: encrypt(user.password),
    phone: user.phone
  };
  return request({
    url: 'users/changePassword',
    method: 'post',
    data
  });
}

export function updatePass(user) {
  const data = {
    oldPass: encrypt(user.oldPass),
    newPass: encrypt(user.newPass)
  };
  return request({
    url: 'users/updatePass/',
    method: 'post',
    data
  });
}

export function resetPwd(ids) {
  return request({
    url: 'users/resetPwd',
    method: 'put',
    data: ids
  });
}

// 角色分配
export function updateRole(data) {
  return request({
    url: 'users/updateRole',
    method: 'post',
    data
  });
}

// 获取角色信息
export function getRoleSelect() {
  return request({
    url: 'roles/select ',
    method: 'get',

  });
}

export function updateEmail(form) {
  const data = {
    password: encrypt(form.pass),
    email: form.email
  };
  return request({
    url: 'users/updateEmail/' + form.code,
    method: 'post',
    data
  });
}

export function freezePoints(data) {
  return request({
    url: '/users/userFreeze',
    method: 'post',
    data
  });
}

export default { add, edit, del, resetPwd, getRoleSelect, updateRole, changePassword, freezePoints }

